package com.lg.partition19;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/4/5 10:15
 */
public class P1853投资的最大效益 {

    private static final int N = 10000000;
    private static int[] w = new int[11], v = new int[11], f = new int[N];
    private static int n, m, k;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] ss = reader.readLine().split(" ");
        m = Integer.parseInt(ss[0]);
        k = Integer.parseInt(ss[1]);
        n = Integer.parseInt(ss[2]);
        for (int i = 1; i <= n; i++) {
            ss = reader.readLine().split(" ");
            int a = Integer.parseInt(ss[0]), b = Integer.parseInt(ss[1]);
            w[i] = b;
            v[i] = a;
        }
        for (int x = 1; x <= k; x++) {
            for (int i = 1; i <= n; i++) {
                for (int j = v[i]; j <= m; j++) {
                    f[j] = Math.max(f[j], f[j - v[i]] + w[i]);
                }
            }
            m += f[m];
        }
        writer.write(m + "\n");
        writer.flush();
    }
}
